Document trailing self in paths#2237
Open
traviscross wants to merge 1 commit intomasterfrom
Open
Conversation
The Reference says that `self` can only appear as the first segment of
a path. Further, the `use` chapter describes `{self}` brace syntax as
the way to bind the parent entity of a `use` path under its own name.
In rust-lang/rust#155137, we're relaxing these restrictions: `self`
may now also appear as the last segment of a path (preceded by `::`)
as long as the preceding path resolves to a module, enumeration,
or trait. In a `use` path, `use P::self [as name]` is equivalent
to `use P::{self [as name]}`. In non-`use` paths, forms such as
`type Ty = P::self` and `pub(in P::self)` are now accepted.
Let's update the Reference to reflect this.
ehuss
approved these changes
Apr 21, 2026
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Apr 27, 2026
…trochenkov Allow trailing `self` in more contexts Reference PR: - rust-lang/reference#2237 As a follow-up PR to rust-lang#152996, after this PR: 1. Trailing `self` can appear in paths 2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};` r? petrochenkov
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Apr 27, 2026
…trochenkov Allow trailing `self` in more contexts Reference PR: - rust-lang/reference#2237 As a follow-up PR to rust-lang#152996, after this PR: 1. Trailing `self` can appear in paths 2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};` r? petrochenkov
rust-timer
added a commit
to rust-lang/rust
that referenced
this pull request
Apr 28, 2026
Rollup merge of #155137 - mu001999-contrib:self-at-end, r=petrochenkov Allow trailing `self` in more contexts Reference PR: - rust-lang/reference#2237 As a follow-up PR to #152996, after this PR: 1. Trailing `self` can appear in paths 2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};` r? petrochenkov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Reference says that
selfcan only appear as the first segment of a path. Further, theusechapter describes{self}brace syntax as the way to bind the parent entity of ausepath under its own name.In rust-lang/rust#155137, we're relaxing these restrictions:
selfmay now also appear as the last segment of a path (preceded by::) as long as the preceding path resolves to a module, enumeration, or trait. In ausepath,use P::self [as name]is equivalent touse P::{self [as name]}. In non-usepaths, forms such astype Ty = P::selfandpub(in P::self)are now accepted.Let's update the Reference to reflect this.
cc @ehuss @mu001999